#include <iostream>
#include <functional>
#include <queue>
//定义Event结构体
struct Event {
    std::function<void()> callback;
};
//定义事件处理器
class EventHandler {
public:
    void handleEvent(Event event) {
        event.callback();
    }
};
//定义事件循环
class EventLoop {
public:
    void addEvent(Event event) {
        eventQueue.push(event);
    }
    void run() {
        while (!eventQueue.empty()) {
            Event event = eventQueue.front();
            eventQueue.pop();
            eventHandler.handleEvent(event);
        }
    }
private:
    std::queue<Event> eventQueue;
    EventHandler eventHandler;
};
int main() {
    //创建事件循环对象
    EventLoop eventLoop;
    //回调函数
    std::function<void()> callback1 = []() {
        std::cout << "Event 1 triggered!" << std::endl;
    };
    std::function<void()> callback2 = []() {
        std::cout << "Event 2 triggered!" << std::endl;
    };
    //创建事件并添加到事件循环中
    Event event1{ callback1 };
    Event event2{ callback2 };
    eventLoop.addEvent(event1);
    eventLoop.addEvent(event2);
    //运行事件循环
    eventLoop.run();
    return 0;
}